package dgut.party.business;

import dgut.party.business.dao.MenuRepository;
import dgut.party.business.dao.publication.PublicationRepository;
import dgut.party.business.dao.rbac.AuthorityRepository;
import dgut.party.business.dao.rbac.RoleRepository;
import dgut.party.business.dao.user.AccountRepository;
import dgut.party.business.dao.user.UserTitleRepository;
import dgut.party.business.mockdata.MockMenusBean;
import dgut.party.business.mockdata.MockPubBean;
import dgut.party.business.mockdata.MockRoleAuthorityBean;
import dgut.party.business.mockdata.MockUsersBean;
import org.springframework.boot.CommandLineRunner;
import org.springframework.boot.SpringApplication;
import org.springframework.boot.autoconfigure.SpringBootApplication;
import org.springframework.context.annotation.Bean;
import org.springframework.security.crypto.bcrypt.BCryptPasswordEncoder;

@SpringBootApplication
public class SimplePartyBusinessJApplication {

  public static void main(String[] args) {
    SpringApplication.run(SimplePartyBusinessJApplication.class, args);
  }

  /**
   * 提供密码加密方法
   * <p>
   * author: Mercy Wu(a3049) 2019年2月27日 下午8:59:55
   *
   * @return
   */
  @Bean
  public BCryptPasswordEncoder bCryptPasswordEncoder() {
    return new BCryptPasswordEncoder();
  }

  @Bean
  public CommandLineRunner injectDatas(
    AccountRepository accountRepo, UserTitleRepository titleRepo,
    RoleRepository roleRepo, AuthorityRepository authRepo,
    MenuRepository menuRepo, PublicationRepository pubRepo,
    BCryptPasswordEncoder bCryptPasswordEncoder) {
    return (args) -> {
      MockRoleAuthorityBean.initAuthority(roleRepo, authRepo);
      MockUsersBean.initAccounts(accountRepo, titleRepo, roleRepo, authRepo, bCryptPasswordEncoder);
      MockMenusBean.initMenus(menuRepo, authRepo);
      MockPubBean.initPubs(pubRepo);
    };
  }

}
